package com.itheima.web.session; /**
 * @author Xiao
 * @date 2021/8/31
 */

import com.itheima.web.pojo.UserDemo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
/**session基本使用*/
@WebServlet("/session01b")
public class SessionDemo01b extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        int age = (int) session.getAttribute("age");
        System.out.println(username + " " + age);
        UserDemo user = (UserDemo) session.getAttribute("user");
        System.out.println(user);
        System.out.println(session);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
